import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate'

Vue.use(Vuex)

export default new Vuex.Store({
  // 持久化插件
  plugins: [
    createPersistedState({ storage: window.sessionStorage })
  ],
  state: {
    nickName: undefined,
    userRole: undefined
  },
  getters: {
  },
  mutations: {
    setNickName(state, nickName) {
      // localStorage.setItem('nickName', nickName)
      state.nickName = nickName
    },
    setUserRole(state, userRole) {
      // localStorage.setItem('userRole', userRole)
      state.userRole = userRole
    },
    removeNickName(state) {
      // localStorage.removeItem('nickName')
      state.nickName = ''
    },
    removeUserRole(state) {
      // localStorage.removeItem('userRole')
      state.userRole = ''
    }
  },
  actions: {
  },
  modules: {
  }
})
